package com.e3.web.core.client;

import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.ServiceDefTarget;

public final class RPCServiceHelper {
	public static final String	SERVICE_URL_PREFIX	= "gwtrpcservice";
	
	/**
	 * register service url
	 * 
	 * @param svcObj
	 *            service object pharos.web.core.service.XXXService => /pharos/pharos.web.core.service.XXXServiceImpl
	 */

	public final static void registerServiceEntryPoint(Object instance) {

		String serviceName = instance.getClass().getName();
		ServiceDefTarget endpoint = (ServiceDefTarget) instance;
		String endpointText = instance.getClass().getName();
		endpointText = endpointText.substring(0, endpointText.indexOf("_Proxy"));
		endpointText = endpointText.substring(endpointText.lastIndexOf(".") + 1);
		endpoint.setServiceEntryPoint(GWT.getHostPageBaseURL() + SERVICE_URL_PREFIX + "/" + endpointText);
		Registry.register(serviceName, instance);
		
	}
	
	public static Object getService(String serviceName){
		return Registry.get(serviceName);
	}
}
